package com.cn.wanxi.servlet;

import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.service.CompanyService;
import com.cn.wanxi.service.ICompanyService;
import com.cn.wanxi.service.INavService;
import com.cn.wanxi.service.INewsService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;
import com.cn.wanxi.service.impl.NavServiceImpl;
import com.cn.wanxi.service.impl.NewsServiceImpl;
import com.cn.wanxi.util.BserModel;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/homeThree")
public class HomeThreeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//  req 前端向后台发送数据叫请求
//        resp 后台向前端发送数据叫响应
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        这里也会出现乱码，前端得到的数据位乱码，但是后端数据正常
//        需要将数据强制转换位utf-8的形式

//        接口的目的，实现多态
        ICompanyService iCompanyService = new CompanyServiceImpl();

        CompanyModel companyModel = iCompanyService.getCompanyModel();
        req.setAttribute("companyModel", companyModel);

        INavService iNavService = new NavServiceImpl();
//        NavModel[] navModels = iNavService.getNavModels();
        List<NavModel> navModelList=iNavService.getNavModelList();
        req.setAttribute("navModels", navModelList);

//------------------------------
        INewsService iNewsService=new NewsServiceImpl();
        req.setAttribute("newsModels",iNewsService.getNewsModelsForHomePage());
        req.getRequestDispatcher("/jsp/home.jsp").forward(req, resp);
    }
}
